package com.jfzt.hgroup.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 后置filter
 *
 * @author wanghaiyong
 */
@Slf4j
public abstract class AbstractPostFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // 后置过滤
        ServerWebExchange serverWebExchange = postFilter(exchange);
        Mono<Void> result = chain.filter(serverWebExchange);
        doPost();
        return result;
    }

    /**
     * 后置业务
     *
     * @param exchange
     * @return
     */
    protected abstract ServerWebExchange postFilter(ServerWebExchange exchange);

    protected void doPost() {

    }
}
